<template>
  <view class="sales-home" :style="`padding-top:${pagePaddingTop}rem`">
    <!-- <Swiper /> -->
    <PointSwiper />
    <CategoryList :list="list" />
    <HealthService :serviceList="recommendServieces" />
    <ProductList title="文朵精选" :list="recommendProducts" />
  </view>
</template>

<script lang="ts">
import "./index.less";
import Taro from "@tarojs/taro";
import CategoryList from "./components/categoryList/index.vue";
import PointSwiper from "./components/pointSwiper/index.vue";
import HealthService from "./components/healthService/index.vue";
import ProductList from "../components/productList/index.vue";
import {
  getProductCategories,
  getProductRecommend,
  ProductType,
} from "../../../services/products-service";

export default {
  components: {
    CategoryList,
    PointSwiper,
    HealthService,
    ProductList,
  },
  data() {
    return {
      list: [],
      recommendProducts: [],
      recommendServieces: [],
      statusBarHeight: 44,
    };
  },
  computed: {
    pagePaddingTop() {
      return this.statusBarHeight / 14;
    },
  },
  methods: {
    async getTotalScore() {},
    async getTaskList() {},
    async getCategories() {
      this.list = await getProductCategories();
      this.$store.commit("setCategories", this.list);
    },
    async getRecommend() {
      const { records } = await getProductRecommend({
        page: 1,
        size: 100,
        is_points_mall: false,
        type: ProductType.PHYSICAL,
      });
      this.recommendProducts = records;
      console.log("setRecommendProducts", records);
      this.$store.commit("setRecommendProducts", this.recommendProducts);
    },
    async getRecommendServiece() {
      const { records } = await getProductRecommend({
        page: 1,
        size: 6,
        type: ProductType.SERVICE,
      });
      this.recommendServieces = records;
      this.$store.commit("setRecommendServices", this.recommendServieces);
    },

    async getPersonalHealthyData() {},
    gotoTaskBrief() {
      Taro.navigateTo({
        url: "",
      });
    },
    getSafeArea() {
      Taro.getSystemInfo().then((info) => {
        this.statusBarHeight = info.statusBarHeight;
      });
    },
  },

  async created() {},
  async mounted() {
    await this.getCategories();
    await this.getRecommendServiece();
    await this.getRecommend();
    this.getSafeArea();
  },

  // onLoad
  onLoad() {},

  // onReady
  onReady() {},

  // 对应 onShow
  onShow() {},

  // 对应 onHide
  onHide() {},

  // 对应 onPullDownRefresh
  onPullDownRefresh() {},
};
</script>
